# -*- coding: utf-8 -*-
# created on 2016/11/30

from mathsolver.functions.shulie.Fundamental import *
from sympy.abc import n


def sl_get_period(eq):
    answer = False
    fn = (eq[0] - eq[1]).expand().simplify()
    max_index, min_index = sl_max_min_index(fn)
    if min_index != n:
        fn = sl_new_an(fn)
    shulie_name = sl_shulie_name(fn)[0]
    a1 = sympify('a')
    an_values = [a1]
    period = None
    for i in range(1, 20):
        new_fn = fn
        new_fn = new_fn.subs({n: i})
        new_fn = new_fn.subs({shulie_name(i): an_values[-1]})
        answers = solve(new_fn, shulie_name(i + 1))
        answer = answers[0]
        if answer == a1:
            answer = True
            period = i
            break
        an_values.append(answer)
    return answer, period, an_values


if __name__ == '__main__':
    pass
